import request from "@/utils/request";

// 文件导入（仅上传单个文件）- 项目资金台账
export function prodProjectFundFileImport(file, porjectId) {
  const formData = new FormData();
  const raw = file && file.raw ? file.raw : file;
  if (raw) {
    // 后端现在只需要一个文件
    formData.append("file", raw);
  }
  // 添加项目ID和台账类型ID参数
  if (porjectId) {
    formData.append("porjectId", porjectId);
  }
  return request({
    url: "/cost/prodProjectFund/importData",
    method: "post",
    data: formData,
    headers: {
      "X-Requested-With": "XMLHttpRequest",
    },
  });
}

// 兼容：如果之前有页面误用该名称，保留一个别名（指向资金台账导入接口）
export const prodProjectLaborFileImport = prodProjectFundFileImport;

// 查询项目资金台账列表
export function listProdProjectFund(query) {
  return request({
    url: "/cost/prodProjectFund/list",
    method: "get",
    params: query,
  });
}

// 查询项目资金台账详细
export function getProdProjectAllCoast(id) {
  return request({
    url: "/cost/prodProjectFund/LoanDetails/" + id,
    method: "get",
  });
}

// 查询项目资金台账所有列表
export function listAllProdProjectFund(query) {
  return request({
    url: "/cost/prodProjectFund/listAll",
    method: "get",
    params: query,
  });
}

// 查询项目资金台账详细
export function getProdProjectFund(id) {
  return request({
    url: "/cost/prodProjectFund/getInfo/" + id,
    method: "get",
  });
}
// 图片上传（仅上传单个文件）
export function addImg(file) {
  const formData = new FormData();
  const raw = file && file.raw ? file.raw : file;
  if (raw) {
    // 后端现在只需要一个文件
    formData.append("file", raw);
  }
  return request({
    url: "/cost/imageStorage/upDataImage",
    method: "post",
    data: formData,
    headers: {
      "X-Requested-With": "XMLHttpRequest",
    },
  });
}
export function delImg(data) {
  return request({
    url: "/cost/imageStorage/delUpDataImage",
    method: "post",
    data: data,
  });
}

// 新增项目资金台账
export function addProdProjectFund(data) {
  return request({
    url: "/cost/prodProjectFund/add",
    method: "post",
    data: data,
  });
}

// 修改项目资金台账
export function updateProdProjectFund(data) {
  return request({
    url: "/cost/prodProjectFund/edit",
    method: "post",
    data: data,
  });
}

// 删除项目资金台账
export function delProdProjectFund(id) {
  return request({
    url: "/cost/prodProjectFund/remove/" + id,
    method: "get",
  });
}
